package momo.multitree.algo;

import momo.multitree.structure.*;

import java.util.LinkedHashMap;
import java.util.LinkedHashSet;

public class CostDijkstra extends ModifiedDijkstra implements OptimumTreeCalculation
{
	
	
	public Tree optimumTree(Graph graph)
	{
		Node[] nodes = graph.getNodes().toArray(new Node[0]) ;
		if ( nodes.length == 0 )
			return null;
		
		Tree initTree = optimumTree(graph, nodes[0]);
		for(int i=1; i<nodes.length; i++)
		{
			Tree nextTree = optimumTree(graph, nodes[i]);
			if ( initTree.compCost(false) > nextTree.compCost(false) )
				initTree = nextTree;
		}
		return initTree;
	}
	
	public double calObjCost(LinkedHashSet<Node> S, Node node, LinkedHashSet<Edge> Et, Edge edgeToAdd, LinkedHashMap<Node, Double> labels) {
		Node[] nodes = S.toArray(new Node[0]);
		Node root = nodes[0];
//		Tree tree = new Tree(root);
//		for(Node n: nodes)
//			tree.add(n);
//		tree.add(node);
//		for(Edge e: Et)
//			tree.add(e);
//		tree.add(edgeToAdd);
		
		Graph g = new Graph();
		for(Node n: nodes)
			g.add(n);
		g.add(node);
		for(Edge e: Et)
			g.add(e);
		g.add(edgeToAdd);
		
		Tree tree = new Tree(root, g);
		
		return tree.compCost(false);
	}
}
